# from datasets.hico_text_label import hico_text_label, hico_text_label_no_object, hico_object2label_index, obj2name, hoi_index2action, action2index, hoi2otherhoi
from datasets.hico_text_label import *

def extract_actions(annotation):
    actions = []
    for hoi_entry in annotation['hoi_annotation']:
        hoi_category_id = hoi_entry['hoi_category_id']
        action = hoi_index2action.get(hoi_category_id, 'unknown_action')  # 使用字典映射获取动作标签，如果找不到则默认为'unknown_action'
        actions.append(action)
    return actions

# # 例如，使用上述示例标签
# sample_annotation = {
#     'file_name': 'HICO_train2015_00000001.jpg',
#     'img_id': 1,
#     'annotations': [{'bbox': [207, 32, 426, 299], 'category_id': 1}, 
#                     {'bbox': [58, 97, 571, 404], 'category_id': 4}],
#     'hoi_annotation': [{'subject_id': 0, 'object_id': 1, 'category_id': 73, 'hoi_category_id': 153}, 
#                         {'subject_id': 0, 'object_id': 1, 'category_id': 77, 'hoi_category_id': 154}, 
#                         {'subject_id': 0, 'object_id': 1, 'category_id': 88, 'hoi_category_id': 155}, 
#                         {'subject_id': 0, 'object_id': 1, 'category_id': 99, 'hoi_category_id': 156}]
# }

# actions = extract_actions(sample_annotation)
# print(actions)  # 输出提取的动作标签
